package com.sevenGroup.pawnshop.controller;


import com.sevenGroup.pawnshop.Utils.Result;
import com.sevenGroup.pawnshop.controller.form.ValuationsForm;
import com.sevenGroup.pawnshop.controller.info.ValuationsInfo;
import com.sevenGroup.pawnshop.model.Valuations;
import com.sevenGroup.pawnshop.service.ValuationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  估价表的前端控制器
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
@RestController
@RequestMapping("/valuations")
@Api(tags = "估价相关的接口")
public class ValuationsController {
    @Resource
    private ValuationsService valuationsService;

//  新增估价表
    @PostMapping("addValuation")
    @ApiOperation("添加估价")
    @PreAuthorize("hasAnyAuthority('boss','shopManage','worker')")
    public Result addValuation(@RequestBody @ApiParam("估价对象") ValuationsForm valuationsForm){
        Integer integer=valuationsService.addValuation(valuationsForm);
        return Result.success(integer);
    }

//  根据商品ID查询估计表集合
    @ApiOperation("查询估价集合")
    @PostMapping("selectValuationByGoodId")
    @PreAuthorize("hasAnyAuthority('boss','shopManage','worker')")
    public Result selectValuationByGoodId(@ApiParam("商品ID") Integer goodId){
        List<ValuationsInfo> valuationsInfoList = valuationsService.selectValuationByGoodId(goodId);
        return Result.success(valuationsInfoList);
    }
}

